/**
 * New node file
 */

var Action = new Function();
Action.prototype.init = function(req, res){
	this.req = req;
	this.res = res;
	switch (req.method) {
		case 'POST': this.post(req, res); break;
		default: this.other(req, res); break;
	}
};

Action.prototype.post = function(req, res){
	var id = req.body.id;
	var oldPassword = req.body.oldPassword;
	var newPassword = req.body.newPassword;
	var action = new (Services('changePassword'))(id, oldPassword, newPassword, {
		success: function(data){
			res.send({ success: true });
			res.end();
		},
		error: function(code, message){
			throw new Exception(code, message, function(){
				res.send(this.toString());
				res.end();
			});
		}
	});
};

Action.prototype.other = function(req, res){
	res.writeHead(404, {
		'Content-Type': 'text/plain',
		'Trailer': 'Content-MD5'
	});
	res.end();
};

module.exports = Action;